﻿using System;
using System.ComponentModel;
using G.Model;

namespace G.Runtime
{
    public abstract class GameValue : 
        System.ICloneable, IEquatable<GameValue>
    {
        public delegate void GameValueChangedHandler(GameValue var);
        public event GameValueChangedHandler ChangedEvent;

        private readonly GameValueDef _GameValueDef;
        
        internal GameValue(GameValueDef def)
        {
            _GameValueDef = def;
        }

        public bool Equals(GameValue other)
        {
            if ((object)other == null)
            {
                return false;
            }

            return (this._GameValueDef.Name == ((GameValue)other)._GameValueDef.Name);
        }

        [Browsable(false)]
        public GameValueDef Def
        {
            get { return _GameValueDef; }
        }

        [Browsable(false)]
        public string DisplayableValue
        {
            get { return FormatDisplayableValue(); }
        }

        protected abstract string FormatDisplayableValue();

        public override string ToString()
        {
            return "" + _GameValueDef.Name;
        }

        public void FireChangedEvent()
        {
            if (ChangedEvent != null)
            {
                ChangedEvent(this);
            }
        }

        public object Clone()
        {
            return base.MemberwiseClone();
        }
        
    }
}
